<!DOCTYPE html>
<#assign base=request.contextPath />
<html lang="en">
<head>
    <base id="base" href="${base}">
    <meta charset="UTF-8">
    <title>服务前端</title>
</head>
<body>
<div align="center">
    <label>选择收货地址</label>
    <div>
        <#list addressList as address>
            <div>
             <input type="checkbox" name="address" value="${address.addressId}"><span>${address.userName}</span>&nbsp;&nbsp;&nbsp;<span>${address.phoneNo}</span>&nbsp;&nbsp;&nbsp;<span>${address.address}</span>
            </div>
         </#list>
    </div>
</div>
<div align="center">
    <table width="100%" border="1px">
        <thead>
        <tr>
            <th width="40%">商品</th>
            <th width="20%">单价</th>
            <th width="20%">数量</th>
            <th width="20%">小计</th>
        </tr>
        </thead>
        <tbody>
        <#if quantity ??>
            <tr align="center">
                <td width="40%"><input type="checkbox" name="productId" value="${product.productId}"><img src="${product.imageUrl}"></td>
                <td width="20%">${product.price}</td>
                <input type="hidden" value="${quantity}" id="quantity">
                <td width="20%">${quantity}</td>
                <td width="20%">${product.price*quantity}</td>
            </tr>
        </tbody>
        </table>
            <span>需付款：￥<i id="total"></i>${product.price*quantity}</span><br>
        <#else >
            <#list productList as product>
            <tr align="center">
                <td width="40%"><input type="checkbox" name="productId" value="${product.productId}"><img src="${product.imageUrl}"></td>
                <td width="20%">${product.price}</td>
                <td width="20%">${product.quantity}</td>
                <td width="20%">${product.price*product.quantity}</td>
            </tr>
            </#list>
        </tbody>
        </table>
            <span>需付款：￥<i id="total"></i></span><br>
        </#if>
    <button id="submitOrder">提交订单</button>
</div>
</body>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>
<script>
    $(function () {
        var base = $("#base").attr("href");
        $("#submitOrder").click(function () {
            var productIds = $("input[name='productId']:checked").val()
            var addressId  = $("input[name='address']:checked").val();
            var quantity = $("#quantity").val();
//                $("input[name='productId']:checked").each(function () {
//                    productIds += this.value + " ";
//                });
//                window.location.href = "submitOrder?productId="+productIds+"&addressId="+addressId+"&quantity="+quantity;
            $.ajax({
                url:base+"/trading/product/submitOrder",
                type:"POST",
                data:{productId:productIds, quantity:quantity, addressId:addressId},
                success:function (data) {
                    if(data){
                        window.location.href = base+"/trading/product/showOrder?id="+data;
                    }
                }
            })
        })
    })
</script>
</html>